package com.gyh.thymeleaf.controller;

import com.github.pagehelper.PageHelper;
import com.gyh.thymeleaf.entity.User;
import com.gyh.thymeleaf.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author gyhstart
 * @create 2020/6/15 - 10:57
 **/

@Api(tags = "thymeleaf 测试模块")
@Controller
@RequestMapping("/api/user")
public class SwaggerController {
    private static final Logger logger = LoggerFactory.getLogger(SwaggerController.class);

    @Autowired
    private UserService userService;

    @GetMapping("/show")
    @ApiOperation(value = "获取所有user", notes = "获取所有user，无需参数", httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径找不到")
    })
    public String show(Model model, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum) {
        //pageNum:表示第几页  pageSize:表示一页展示的数据
        PageHelper.startPage(pageNum,3);
        List<User> list = userService.selectList();
        //将查询到的数据封装到PageInfo对象
        //PageInfo<User> pageInfo = new PageInfo<>(list,2);
        model.addAttribute("list", list);
        return "login";
    }

//    @GetMapping("/login")
//    @ApiOperation(value = "登录", notes = "使用SpringSecurity", httpMethod = "GET")
//    public String login(User user) {
//        List<User> userList = userService.login(user);
//       if(null == userList || userList.size() ==0){
//           System.out.println("登陆失败");
//           return "login";
//       }
//        System.out.println("登陆成功");
//        return "dashboard";
//    }

    @GetMapping({"/index","/"})
    public String major(){
        return "login";
    }

    @GetMapping({"/swagger"})
    public String swagger(){
        return "swagger";
    }
}
